const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin'); // 加载html模板文件

// 定义路径
const ROOT_PATH = path.resolve(__dirname); // 注意:__dirname是当前文件的路径
const SRC_PATH = path.resolve(ROOT_PATH, '../src');
const DIST_PATH = path.resolve(ROOT_PATH, '../dist');


module.exports = {
    mode: 'none',
    entry: {
        // 入口
        app: path.join(SRC_PATH, 'app.jsx'),
    },
    output: {
        // 输出配置
        path: DIST_PATH,
        filename: 'js/[name].[hash:5].js'
    },
    resolve: {
        extensions: ['*', '.js', '.jsx', '.json']
    },
    module: {
        rules: [{
                // 配置解析js、jsx
                test: /\.(js|jsx)$/,
                use: {
                    loader: 'babel-loader'
                },
                include: SRC_PATH,
                exclude: path.resolve(ROOT_PATH, 'node_modules')
            },

            {
                // 配置解析图片
                test: /\.(png|gif|jpg|jpeg|bmp)$/,
                use: {
                    loader: 'url-loader',
                    options: {
                        limit: '8192'
                    }
                }
            },
            {
                // 配置解析字体文件
                test: /\.(woff|woff2|svg|ttf|eot)($|\?)/,
                use: {
                    loader: 'url-loader',
                    options: {
                        limit: '8192'
                    }
                }
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({ // 配置html模板页面 
            template: path.join(SRC_PATH, './template/index.html'),
            chunks: ['runtime', 'vendor', 'app']
        }),
        // new BundleAnalyzerPlugin({
        //     // Can be `server`, `static` or `disabled`.
        //     // In `server` mode analyzer will start HTTP server to show bundle report.
        //     // In `static` mode single HTML file with bundle report will be generated.
        //     // In `disabled` mode you can use this plugin to just generate Webpack Stats JSON file by setting `generateStatsFile` to `true`.
        //     analyzerMode: 'server',
        //     // Host that will be used in `server` mode to start HTTP server.
        //     analyzerHost: '127.0.0.1',
        //     // Port that will be used in `server` mode to start HTTP server.
        //     analyzerPort: 8888,
        //     // Path to bundle report file that will be generated in `static` mode.
        //     // Relative to bundles output directory.
        //     reportFilename: 'report.html',
        //     // Automatically open report in default browser
        //     openAnalyzer: true,
        //     // If `true`, Webpack Stats JSON file will be generated in bundles output directory
        //     generateStatsFile: false,
        //     // Name of Webpack Stats JSON file that will be generated if `generateStatsFile` is `true`.
        //     // Relative to bundles output directory.
        //     statsFilename: 'stats.json',
        //     // Options for `stats.toJson()` method.
        //     // For example you can exclude sources of your modules from stats file with `source: false` option.
        //     // See more options here: https://github.com/webpack/webpack/blob/webpack-1/lib/Stats.js#L21
        //     statsOptions: null,
        //     // Log level. Can be 'info', 'warn', 'error' or 'silent'.
        //     logLevel: 'info'
        // }), 
    ],

}